package com.neusoft.neuiotms.dcom.controller.report;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.report.ReportToolDTO;
import com.neusoft.neuiotms.dcom.service.report.ReportToolService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "报表配置")
@RestController
@RequestMapping(value = "/api/w/reportTool")
public class ReportToolController {

    @Autowired
    private ReportToolService reportToolService;

    @ApiOperation("查询所有报表配置")
    @GetMapping
    public ResultListDTO<ReportToolDTO> index(final Searchable searchable) {
        final List<ReportToolDTO> DTOs = this.reportToolService.index(searchable);
        final ResultListDTO<ReportToolDTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("分页查询所有报表配置")
    @GetMapping("/p")
    public PageResultDTO<ReportToolDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.reportToolService.search(pageable, searchable));
    }

    @ApiOperation("创建报表配置")
    @PostMapping("")
    public ResultDTO<ReportToolDTO> create(@RequestBody final ReportToolDTO dto) {
        final ReportToolDTO result = this.reportToolService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation(value = "修改报表配置")
    @PutMapping("/{id}")
    public ResultDTO<ReportToolDTO> update(@PathVariable final Long id,
            @RequestBody final ReportToolDTO dto) {
        final ReportToolDTO result = this.reportToolService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("报表配置详情")
    @GetMapping("/{id}")
    public ResultDTO<ReportToolDTO> details(@PathVariable final Long id) {
        final ReportToolDTO dto = this.reportToolService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除报表配置")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.reportToolService.delete(id);
        return ResultDTO.success();
    }

    @ApiOperation("报表数据")
    @GetMapping("/reportData")
    public PageResultDTO<Map<String, Object>> reportData(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.reportToolService.reportData(pageable, searchable));
    }

}
